package org.example.platform.design.simplefactory.version2.me;


import org.example.platform.design.simplefactory.version2.Futil;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 简单工厂   第2版
 */
public class Factory {

    @Autowired
    MethodServiceImpl methodServiceImpl;

    /**
     * 第2版
     * 输入两个数字，一个运算符，得出结果
     * 使用继承和多态
     *
     * @param num
     * @param num2
     * @param fh
     */
    public void inputNum2(Integer num, Integer num2, String fh) throws Exception {
        try {
            Futil.isNumNotNull(num);
            Futil.isNum2NotNull(num2);
            Futil.isFhNotNull(fh);
        } catch (Exception e) {
           throw new Exception(e.getMessage());
        }

        double result = 0;
        switch (fh) {
            case "*":
                result = methodServiceImpl.mult(num,num2);
                break;
            case "-":
                result = methodServiceImpl.reduce(num,num2);
                break;
            case "/":
                result = methodServiceImpl.except(num,num2);
                break;
            case "+":
                result = methodServiceImpl.add(num,num2);
                break;
        }
        System.out.println(result);
    }

    public static void main(String[] args) {
        int num = 6;
        int num2 = 7;
        String fh = "*";
        double result = 0;
        switch (fh) {
            case "*":
                result = num * num2;
                break;
            case "-":
                result = num - num2;
                break;
            case "/":
                result = num / num2;
                break;
            case "+":
                result = num + num2;
                break;
        }
        System.out.println(result);
    }
}
